home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / control / server / weapons / tommygun.cs < prev    next >
Encoding:
Text File  |  2006-09-24  |  11.6 KB  |  412 lines

  1. datablock AudioProfile(TommyGunMountSound)
  2. {
  3.    filename    = "~/data/sound/shortreload.wav";
  4.    description = AudioClose3d;
  5.    preload = true;
  6. };
  7.  
  8. datablock AudioProfile(TommyGunReloadSound)
  9. {
  10.    filename    = "~/data/sound//Weapon_pickup.wav";
  11.    description = AudioClose3d;
  12.    preload = true;
  13. };
  14.  
  15. datablock AudioProfile(TommyGunFireSound)
  16. {
  17.    filename    = "~/data/sound/tommygun.wav";
  18.    description = AudioClose3d;
  19.    preload = true;
  20. };
  21.  
  22. datablock AudioProfile(TommyGunDryFireSound)
  23. {
  24.    filename    = "~/data/sound/dryfire.wav";
  25.    description = AudioClose3d;
  26.    preload = true;
  27. };
  28.  
  29. datablock AudioProfile(WeaponSwitchSound)
  30. {
  31.    filename    = "~/data/sound/Weapon_switch.wav";
  32.    description = AudioClose3d;
  33.    preload = true;
  34. };
  35.  
  36. //-----------------------------------------------------------------------------
  37. // Projectile trail emitter
  38.  
  39. datablock ParticleData(TommyGunSmoke)
  40. {
  41.    textureName          = "~/data/particles/smoke";
  42.  
  43.    dragCoeffiecient     = 0.0;
  44.    gravityCoefficient   = -0.2;  // rises
  45.    inheritedVelFactor   = 0.00;
  46.  
  47.    lifetimeMS           = 300;   // time in ms
  48.    lifetimeVarianceMS   = 150;   // ...more or less
  49.  
  50.    useInvAlpha = false;
  51.    spinRandomMin = -30.0;
  52.    spinRandomMax = 30.0;
  53.  
  54.    colors[0]     = "0 0.2 1 1.0";
  55.    colors[1]     = "0 0.2 1 1.0";
  56.    colors[2]     = "0 0 0 0";
  57.  
  58.    sizes[0]      = 0.25;
  59.    sizes[1]      = 0.4;
  60.    sizes[2]      = 0.6;
  61.  
  62.    times[0]      = 0.0;
  63.    times[1]      = 0.3;
  64.    times[2]      = 1.0;
  65. };
  66.  
  67. datablock ParticleEmitterData(TommyGunSmokeEmitter)
  68. {
  69.    ejectionPeriodMS = 10;
  70.    periodVarianceMS = 5;
  71.  
  72.    ejectionVelocity = 0.25;
  73.    velocityVariance = 0.10;
  74.  
  75.    thetaMin         = 0.0;
  76.    thetaMax         = 90.0;
  77.  
  78.    particles = TommyGunsmoke;
  79. };
  80.  
  81.  
  82. //-----------------------------------------------------------------------------
  83. // Weapon fire emitter
  84.  
  85. datablock ParticleData(TommyGunFireParticle)
  86. {
  87.    textureName          = "~/data/particles/smoke";
  88.  
  89.    dragCoeffiecient     = 0.0;
  90.    gravityCoefficient   = -0.1;  // rises
  91.    inheritedVelFactor   = 0.3;
  92.  
  93.    lifetimeMS           = 200;   // Time in ms
  94.    lifetimeVarianceMS   = 50;    // ...more or less
  95.  
  96.    useInvAlpha = false;
  97.    spinRandomMin = -30.0;
  98.    spinRandomMax = 30.0;
  99.  
  100.    colors[0]     = "1 0.6 1 1.0";
  101.    colors[1]     = "1 1 1 1.0";
  102.    colors[2]     = "1 0 0 0";
  103.  
  104.    sizes[0]      = 0.1;
  105.    sizes[1]      = 0.4;
  106.    sizes[2]      = 0.6;
  107.  
  108.    times[0]      = 0.0;
  109.    times[1]      = 0.3;
  110.    times[2]      = 1.0;
  111. };
  112.  
  113. datablock ParticleEmitterData(TommyGunFireEmitter)
  114. {
  115.    ejectionPeriodMS = 30;
  116.    periodVarianceMS = 5;
  117.  
  118.    ejectionVelocity = 2;
  119.    ejectionOffset   = 0.1;
  120.    velocityVariance = 0.10;
  121.  
  122.    thetaMin         = 0.0;
  123.    thetaMax         = 10.0;
  124.  
  125.    particles = TommyGunFireParticle;
  126. };
  127.  
  128.  
  129. //-----------------------------------------------------------------------------
  130. // Projectile Explosion
  131.  
  132. datablock ParticleData(TommyGunExplosionParticle)
  133. {
  134.    dragCoefficient      = 2;
  135.    gravityCoefficient   = 0.2;
  136.    inheritedVelFactor   = 0.2;
  137.    constantAcceleration = 0.0;
  138.    lifetimeMS           = 250;
  139.    lifetimeVarianceMS   = 50;
  140.    textureName          = "~/data/particles/smoke";
  141.    colors[0]     = "0.2 0.2 0.2 1.0";
  142.    colors[1]     = "0.2 0.2 0.2 0.0";
  143.    sizes[0]      = 0.1;
  144.    sizes[1]      = 0.05;
  145. };
  146.  
  147. datablock ParticleEmitterData(TommyGunExplosionEmitter)
  148. {
  149.    ejectionPeriodMS = 7;
  150.    periodVarianceMS = 0;
  151.    ejectionVelocity = 1;
  152.    velocityVariance = 1.0;
  153.    ejectionOffset   = 0.0;
  154.    thetaMin         = 0;
  155.    thetaMax         = 60;
  156.    phiReferenceVel  = 0;
  157.    phiVariance      = 360;
  158.    overrideAdvances = false;
  159.    particles = "TommyGunExplosionParticle";
  160. };
  161.  
  162. datablock ExplosionData(TommyGunExplosion)
  163. {
  164.    //explosionShape = "~/data/models/weapons/explosion.dts";
  165.  
  166.    particleEmitter = TommyGunExplosionEmitter;
  167.    particleDensity = 10;
  168.    particleRadius = 0.1;
  169.  
  170.    faceViewer     = true;
  171.    explosionScale = ".2 .2 .2";
  172.  
  173.    shakeCamera = false;
  174.    camShakeFreq = "10.0 11.0 10.0";
  175.    camShakeAmp = "1.0 1.0 1.0";
  176.    camShakeDuration = 0.5;
  177.    camShakeRadius = 10.0;
  178. };
  179.  
  180.  
  181. //-----------------------------------------------------------------------------
  182. // Projectile Object
  183.  
  184. datablock ProjectileData(TommyGunProjectile)
  185. {
  186.    projectileShapeName = "~/data/models/weapons/tgprojectile.dts";
  187.    directDamage        = 15;
  188.    radiusDamage        = 5;
  189.    damageRadius        = 0.7;
  190.    explosion           = TommyGunExplosion;
  191.   // particleEmitter     = TommyGunSmokeEmitter;
  192.  
  193.    muzzleVelocity      = 700;
  194.    velInheritFactor    = 1;
  195.  
  196.    armingDelay         = 0;
  197.    lifetime            = 2500;
  198.    fadeDelay           = 1500;
  199.    bounceElasticity    = 0;
  200.    bounceFriction      = 0;
  201.    isBallistic         = true;
  202.    gravityMod = 0.10;
  203.  
  204.    hasLight    = true;
  205.    lightRadius = 6.0;
  206.    lightColor  = "0.2 0.2 0.2";
  207. };
  208.  
  209. function TommyGunProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
  210. {
  211.    // Apply damage to the object all shape base objects
  212.    if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
  213.       %col.damage(%obj,%pos,%this.directDamage,"TommyGunBullet");
  214.  
  215.    // Radius damage is a support scripts defined in radiusDamage.cs
  216.    radiusDamage(%obj,%pos,%this.damageRadius,%this.radiusDamage,"TommyGunBullet",0);
  217. }
  218.  
  219.  
  220. //-----------------------------------------------------------------------------
  221. // Ammo Item
  222.  
  223. datablock ItemData(TommyGunAmmo)
  224. {
  225.    // Mission editor category
  226.    category = "Ammo";
  227.  
  228.    // Add the Ammo namespace as a parent.  The ammo namespace provides
  229.    // common ammo related functions and hooks into the inventory system.
  230.    className = "Ammo";
  231.  
  232.    // Basic Item properties
  233.    shapeFile = "~/data/models/weapons/tgammo.dts";
  234.    mass = 0.5;
  235.    elasticity = 0.2;
  236.    friction = 0.4;
  237.  
  238.     // Dynamic properties defined by the scripts
  239.     pickUpName = ".45 Cal ammo";
  240.    maxInventory = 30;
  241. };
  242.  
  243.  
  244. //--------------------------------------------------------------------------
  245. // TommyGun shell that's ejected during reload.
  246.  
  247. datablock DebrisData(TommyGunShell)
  248. {
  249.    shapeFile = "~/data/models/weapons/tgshell.dts";
  250.    lifetime = 3.0;
  251.    minSpinSpeed = 300.0;
  252.    maxSpinSpeed = 400.0;
  253.    elasticity = 0.5;
  254.    friction = 0.2;
  255.    numBounces = 4;
  256.    staticOnMaxBounce = true;
  257.    snapOnMaxBounce = false;
  258.    fade = true;
  259. };
  260.  
  261.  
  262. //--------------------------------------------------------------------------
  263. // Weapon Item.  This is the item that exists in the world, i.e. when it's
  264. // been dropped, thrown or is acting as re-spawnable item.  When the weapon
  265. // is mounted onto a shape, the TommyGunImage is used.
  266.  
  267. datablock ItemData(TommyGun)
  268. {
  269.    // Mission editor category
  270.    category = "Weapon";
  271.  
  272.    // Hook into Item Weapon class hierarchy. The weapon namespace
  273.    // provides common weapon handling functions in addition to hooks
  274.    // into the inventory system.
  275.    className = "Weapon";
  276.  
  277.    // Basic Item properties
  278.    shapeFile = "~/data/models/weapons/TommyGun.dts";
  279.    mass = 1.5;
  280.    elasticity = 0.1;
  281.    friction = 0.9;
  282.    emap = true;
  283.  
  284.     // Dynamic properties defined by the scripts
  285.     pickUpName = "a sub-machinegun";
  286.     image = TommyGunImage;
  287. };
  288.  
  289.  
  290. //-----------------------------------------------------------------------------
  291.  
  292. function TommyGunImage::onFire(%this, %obj, %slot)
  293. {
  294.    %projectile = %this.projectile;
  295.  
  296.    // Decrement inventory ammo. The image's ammo state is update
  297.    // automatically by the ammo inventory hooks.
  298.    %obj.decInventory(%this.ammo,1);
  299.  
  300.    // Determin initial projectile velocity based on the
  301.    // gun's muzzle point and the object's current velocity
  302.    %muzzleVelocity = %obj.getMuzzleVector(%slot);
  303.    %objectVelocity = %obj.getVelocity();
  304.    %velocity = VectorAdd(
  305.       VectorScale(%muzzleVelocity, %projectile.muzzleVelocity),
  306.       VectorScale(%objectVelocity, %projectile.velInheritFactor));
  307.  
  308.    // Create the projectile object
  309.    %p = new (%this.projectileType)() {
  310.       dataBlock        = %projectile;
  311.       initialVelocity  = %velocity;
  312.       initialPosition  = %obj.getMuzzlePoint(%slot);
  313.       sourceObject     = %obj;
  314.       sourceSlot       = %slot;
  315.       client           = %obj.client;
  316.    };
  317.    MissionCleanup.add(%p);
  318.    return %p;
  319. }
  320.  
  321. //--------------------------------------------------------------------------
  322. // TommyGun image which does all the work.  Images do not normally exist in
  323. // the world, they can only be mounted on ShapeBase objects.
  324.  
  325. datablock ShapeBaseImageData(TommyGunImage)
  326. {
  327.    shapeFile = "~/data/models/weapons/TommyGun.dts";
  328.    offset = "0 0 0";
  329.    mountPoint = 0;
  330.    emap = true;
  331.  
  332.    className = "WeaponImage";
  333.  
  334.    item = TommyGun;
  335.    ammo = TommyGunAmmo;
  336.    projectile = TommyGunProjectile;
  337.    projectileType = Projectile;
  338.    casing = TommyGunShell;
  339.    armThread = "look2";
  340.  
  341.    // State Data
  342.    stateName[0]                     = "Preactivate";
  343.    stateTransitionOnLoaded[0]       = "Activate";
  344.    stateTransitionOnNoAmmo[0]       = "NoAmmo";
  345.  
  346.    stateName[1]                     = "Activate";
  347.    stateTransitionOnTimeout[1]      = "Ready";
  348.    stateTimeoutValue[1]             = 0.7;
  349.    stateSequence[1]                 = "Activated";
  350.    stateSound[1]                    = WeaponSwitchSound;
  351.  
  352.    stateName[2]                     = "Ready";
  353.    stateTransitionOnNoAmmo[2]       = "NoAmmo";
  354.    stateTransitionOnTriggerDown[2]  = "Fire";
  355.    stateScript[2]                   = "onReady";
  356.    stateTransitionOnReload[2]       = "Reload";
  357.  
  358.  
  359.    stateName[3]                     = "Fire";
  360.    stateTransitionOnTimeout[3]      = "Ready";
  361.    stateTimeoutValue[3]             = 0.096;
  362.    stateFire[3]                     = true;
  363.    stateRecoil[3]                   = LightRecoil;
  364.    stateAllowImageChange[3]         = false;
  365.    stateSequence[3]                 = "Fire";
  366.    stateScript[3]                   = "onFire";
  367.    stateSound[3]                    = TommyGunFireSound;
  368.    stateEmitter[3]                  = TommyGunFireEmitter;
  369.    stateEmitterTime[3]              = 1.0;
  370.    stateEmitterNode[3]              = "muzzlePoint";
  371.  
  372.    stateName[4]                     = "Reload";
  373.    stateTransitionOnNoAmmo[4]       = "NoAmmo";
  374.    stateTransitionOnTimeout[4]      = "FinishedReloading";
  375.    stateTimeoutValue[4]             = 3.5; // 0.25 load, 0.25 spinup
  376.    stateAllowImageChange[4]         = false;
  377.    stateSequence[4]                 = "Reload";
  378.    stateScript[4]                   = "onReload";
  379.    stateSound[4]                    = TommyGunReloadSound;
  380.  
  381.  
  382.    stateName[5]                     = "FinishedReloading";
  383.    stateTransitionOnTimeout[5]      = "Activate";
  384.    stateTimeoutValue[5]             = 0.04;
  385.    stateScript[5]                   = "onFinishedReloading";
  386.  
  387.    stateName[6]                     = "NoAmmo";
  388.    stateTransitionOnAmmo[6]         = "Reload";
  389.    stateSequence[6]                 = "NoAmmo";
  390.    stateScript[6]                   = "onNoAmmo";
  391.    stateTransitionOnTriggerDown[6]  = "DryFire";
  392.  
  393.    stateName[7]                     = "DryFire";
  394.    stateSound[7]                    = TommyGunDryFireSound;
  395.    stateScript[7]                   = "onDryFire";
  396.    stateTimeoutValue[7]             = 0.5;
  397.    stateTransitionOnTimeout[7]      = "NoAmmo";
  398.  
  399.    stateName[8]                     = "WaitTriggerRelease";
  400.    stateScript[8]                   = "onWaitTriggerRelease";
  401.    stateTransitionOnTimeout[8]      = "WaitTriggerRelease";
  402.    stateTimeoutValue[8]             = 0.01;
  403.    stateTransitionOnTriggerUp[8]    = "Ready";
  404.  
  405.    autoFire = true;
  406.    weaponDamage = 60;
  407.    minSpread = 0.01;
  408.    maxSpread = 0.045;
  409.    spreadRate = 0.019;   // amount spread should increase per shot
  410.    spreadRecoverRate = 0.003;
  411. };
  412.